Copyright ã1992 by Scott Hess.  All Rights Reserved.

Expert Use of OSC Sequences

In Examples, I give the simplest use of OSC sequences to update the Directory preference for Stuart windows by using the osc utility.  The use of osc to output the sequences, while simple, is generally not the most efficient solution available.  Most shells provide a built-in echo command which runs many times faster than any external command could run.  As an example, here's the tcsh example rewritten to use the built-in echo:

alias cwdcmd 'echo -n "^[]3;$cwd^G"'

`^[' is ESC and is entered using `Control-V Esc' in most shells, and in vi.  Use `Control-Q Esc' in emacs.  `^G' terminates the string and is entered using `Control-V Control-G'.  You cannot use Edit to enter these sequences into your startup files, because Edit doesn't allow entry of Control characters.  I will leave it to the user to convert the other commands to use echo instead of osc.

In some cases, you can even do better than use of the built-in echo.  With tcsh, you could also output the sequence as part of the tcsh prompt.  Under tcsh, you can add the string `%{^[]3;%/^G%} ' to your prompt variable.  Again, `^[' is ESC and `^G' is Control-G.  Also, note the space after the `}' character.  This is required by tcsh.

The the use of the shell's built-in echo is mainly applicable to sending OSC sequences to Stuart as part of changing directories.  In many cases, it is much easier to just use osc, since you do not have to enter control sequences or remember the codes to send.  For instance, when setting your titlebar on startup as described in Tricks, the slight time difference between using osc and a built-in echo is not worth worrying about, because you only perform the operation once per shell startup.  The speed advantage of the built-in echo is only significant when the operation will be executed often.